package com.atguigu.tingshu.user.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.security.AuthProvider;

/**
 * ClassName: WeChatMpConfig
 * Package: com.atguigu.tingshu.user.config
 * Description:
 *
 * @Author ycy
 * @Create 2024/9/12 11:22
 * @Version 1.0
 */
@Component
public class WeChatMpConfig {
    @Autowired
    private WechatAccountConfig wechatAccountConfig;

    @Bean
    public WxMaService wxMaService(){

        // 创建对象
        WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();
        wxMaDefaultConfig.setAppid(wechatAccountConfig.getAppId());
        wxMaDefaultConfig.setSecret(wechatAccountConfig.getAppSecret());
        wxMaDefaultConfig.setMsgDataFormat("JSON");

        // 创建 WxMaService 对象
        WxMaService service = new WxMaServiceImpl();

        // 给 WxMaService 设置配置选项
        service.setWxMaConfig(wxMaDefaultConfig);
        return service;
    }
}
